/**
 * @description router全局配置，如有必要可分文件抽离，其中asyncRoutes只有在intelligence模式下才会用到，vip文档中已提供路由的基础图标与小清新图标的配置方案，请仔细阅读
 */

import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '@/layouts'
import EmptyLayout from '@/layouts/EmptyLayout'
import { publicPath, routerMode } from '@/config'

Vue.use(VueRouter)
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'), // 登录页面
    hidden: true,
  },
  {
    path: '/register',
    component: () => import('@/views/register/index'), // 注册页面
    hidden: true,
  },
  // },
  // {
  //   path: '/401',
  //   name: '401',
  //   component: () => import('@/views/401'),
  //   hidden: true,
  // },
  // {
  //   path: '/404',
  //   name: '404',
  //   component: () => import('@/views/404'),
  //   hidden: true,
  // },
]

export const asyncRoutes = [
  {
    path: '/',
    component: Layout,
    redirect: '/index',
    children: [
      {
        path: 'index',
        name: 'Index',
        component: () => import('@/views/index/index'),
        meta: {
          title: '系统首页',
          icon: 'home',
          affix: true,
        },
      },
    ],
  },
  {
    path: '/blog',
    component: Layout,
    redirect: 'noRedirect',
    name: 'Blog',
    meta: { title: '博客管理', icon: 'users-cog', permissions: ['admin'] },
    children: [
      {
        path: 'blogManagement',
        name: 'BlogManagement',
        component: () => import('@/views/index/blog/index'),
        meta: {
          title: '博客管理',
          icon: 'home',
          affix: true,
        },
      },
      {
        path: 'blogWrite',
        name: 'BlogWrite',
        component: () => import('@/views/index/write/index'),
        meta: {
          title: '写博客',
          icon: 'home',
          affix: true,
        },
      },
      {
        path: 'blogQuery',
        name: 'BlogQuery',
        // component: () => import('@/views/index/index'),
        meta: {
          title: '查询博客',
          icon: 'home',
          affix: true,
        },
      },
      {
        path: 'categoryManagement',
        name: 'CategoryManagement',
        // component: () => import('@/views/index/index'),
        meta: {
          title: '类别管理',
          icon: 'home',
          affix: true,
        },
      },
    ],
  },
  {
    path: '/statisticalChart',
    component: Layout,
    redirect: 'noRedirect',
    component: () => import('@/views/index/index'),
    meta: {
      title: '统计图表',
      icon: 'home',
      affix: true,
    },
  },
  {
    path: '/operateLog',
    component: Layout,
    redirect: 'noRedirect',
    component: () => import('@/views/index/index'),
    meta: {
      title: '操作日志',
      icon: 'home',
      affix: true,
    },
  },
  {
    path: '/commontMangement',
    component: Layout,
    redirect: 'noRedirect',
    component: () => import('@/views/index/index'),
    meta: {
      title: '评论管理',
      icon: 'home',
      affix: true,
    },
  },
  {
    path: '/crawlArticle',
    component: Layout,
    redirect: 'noRedirect',
    component: () => import('@/views/index/index'),
    meta: {
      title: '爬取文章',
      icon: 'home',
      affix: true,
    },
  },
  {
    path: '/visit',
    component: Layout,
    redirect: 'noRedirect',
    name: 'Visit',
    meta: { title: '访问模块', icon: 'users-cog', permissions: ['admin'] },
    children: [
      {
        path: 'visitRecoard',
        name: 'VisitRecoard',
        component: () => import('@/views/index/index'),
        meta: {
          title: '访问记录',
          icon: 'home',
          affix: true,
        },
      },
      {
        path: 'visitStatistics',
        name: 'VisitStatistics',
        component: () => import('@/views/index/index'),
        meta: {
          title: '访问统计',
          icon: 'home',
          affix: true,
        },
      },
      {
        path: 'blacklist',
        name: 'Blacklist',
        component: () => import('@/views/index/index'),
        meta: {
          title: '黑名单',
          icon: 'home',
          affix: true,
        },
      },
    ],
  },
  {
    path: '/personnelManagement',
    component: Layout,
    redirect: 'noRedirect',
    name: 'PersonnelManagement',
    meta: { title: '系统管理', icon: 'users-cog', permissions: ['admin'] },
    children: [
      {
        path: 'userManagement',
        name: 'UserManagement',
        component: () =>
          import('@/views/personnelManagement/userManagement/index'),
        meta: { title: '用户管理' },
      },
      {
        path: 'roleManagement',
        name: 'RoleManagement',
        component: () =>
          import('@/views/personnelManagement/roleManagement/index'),
        meta: { title: '角色管理' },
      },
      {
        path: 'menuManagement',
        name: 'MenuManagement',
        component: () =>
          import('@/views/personnelManagement/menuManagement/index'),
        meta: { title: '菜单管理', badge: 'New' },
      },
    ],
  },
]

const router = new VueRouter({
  base: publicPath,
  mode: routerMode,
  scrollBehavior: () => ({
    y: 0,
  }),
  routes: constantRoutes,
})

export function resetRouter() {
  location.reload()
}

export default router
